package com.example.service;

import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Override
    public void add(String pname, int number) {
        System.out.println("购买了 [" + pname + "] " + number + " 个");
        // 模拟方法执行时间
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }

    @Override
    public void delete(String pname) {
        System.out.println("从购物车中删除了 [" + pname + "]");
        // 模拟方法执行时间
        try {
            Thread.sleep(30);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }

    @Override
    public int find(String pname) {
        // 模拟查询到的数量
        int count = (int)(Math.random() * 10) + 1;
        System.out.println("查询 [" + pname + "] 的数量");
        // 模拟方法执行时间
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        return count;
    }
}
    